package br.com.cadastro.persistencia.dao;


import java.util.HashMap;
import java.util.List;

import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;

import br.com.cadastro.entidade.Usuario;
import br.com.cadastro.hibernate.util.HibernateUtil;

public class UsuarioDAO{
	
	private SessionFactory factory;
	
	public UsuarioDAO() throws Exception{
		factory = HibernateUtil.getSessionFactory();
		
	}     
	
	@SuppressWarnings("unchecked")
	public List<Usuario> listarTodos(){
		Session session = factory.openSession();
        session.beginTransaction();
        List<Usuario> result = session.createQuery("from Usuario").list();
        session.getTransaction().commit();
        return result;
	}
	
	public void inserir(Usuario us) throws Exception {
		Session session = factory.openSession();
		session.save(us);
		session.flush();
		session.close();
	}
	
	public void alterar(Usuario us) throws Exception {
		Session session = factory.openSession();
		session.update(us);
		session.flush();
		session.close();
	}
	public void excluir(Usuario us) throws Exception {
		Session session = factory.openSession();
		session.delete(us);
		session.flush();
		session.close();
	}

	public boolean checaLogin(String username, String senha, HashMap<?,?> hashMap) {
		return false;
	}

}